package com.ld.admin.controller.oa.work;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ld.admin.controller.AdminBasicController;
import com.ld.admin.model.oa.work.TodayTaskModel;
import com.ld.admin.model.oa.work.WeeklyReportModel;
import com.ld.admin.service.oa.work.OaWeeklyReportService;
import com.ld.shieldsb.common.web.util.Web;
import com.ld.shieldsb.dao.model.QueryModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 
 * 工作周报
 * 
 * @ClassName OaWeeklyReportController
 * @author 马如海
 * @date 2019年08月19日 10:25:14
 *
 */
@Api(tags = "工作周报")
@Controller(value = "")
@RequestMapping("${shieldsb.adminPath}/oa/work/weeklyReport")
public class OaWeeklyReportController extends AdminBasicController<WeeklyReportModel> {

    @Autowired
    private OaWeeklyReportService weeklyReportService;

    /**
     * 
     * 周报生成
     * 
     * @Title weeklyNewpaper
     * @author 马如海
     * @date 2019年8月19日 上午9:49:21
     * @return Object
     */
    @ApiOperation(value = "周报生成", notes = "")
    @RequestMapping(path = "/oaweeklyReport", method = RequestMethod.GET)
    public Object OaWeeklyReport() {
        setAttributes();
        QueryModel queryModel = weeklyReportService.getSearchQueryModel(request);
        queryModel.addEq("createBy", Web.Util.getSessionUserId(request));
        List<TodayTaskModel> list = weeklyReportService.getList(request, TodayTaskModel.class, queryModel);
        double totalHours = list.stream().mapToDouble(TodayTaskModel -> TodayTaskModel.getTimeConsuming()).sum();
        request.setAttribute("totalHours", totalHours);
        request.setAttribute("username", Web.Util.getSessionUser(request).getUserName());
        return "a/oa/work/todaytask/weekly_report_show";
    }
}